Page({
  data: {
    one_img:'./image/1-point.png',
    two_img: './image/1-point.png',
    three_img: './image/1-point.png',
    flag:true,
    timer:null,
    msg:'摇一摇',
    total:0,
    txt:'恭喜你摇到了：0',
    arr:[//六张图片写进一个数组
      './image/1-point.png',
      './image/2-point.png',
      './image/3-point.png',
      './image/4-point.png',
      './image/5-point.png',
      './image/6-point.png',
    ]
  },
  enter:function(event){
    let obj = this;
    if(obj.data.flag){
       obj.data.timer = setInterval(function () {
        let one = Math.floor(Math.random() * 6);//Math.random是0-5随机数
        let two = Math.floor(Math.random() * 6);
        let three = Math.floor(Math.random() * 6);
        obj.setData({//在setDate中改变值，将随机数作为数组下标来给三个位置的图片填入不同图片
          one_img: obj.data.arr[one],
          two_img: obj.data.arr[two],
          three_img: obj.data.arr[three],
          flag:false,
          msg:'停止',
          total:one+two+three+3,//要加3是因为筛子从1开始而随机数从0开始
          txt:'',
        })
      }, 50);
    }else{
      clearInterval(obj.data.timer);
      obj.setData({
           msg:'摇一摇',
           flag:true,
           txt:'恭喜你摇到了:'+obj.data.total,
      })
    }
  },
})


